package com.cn.crmsystem.service.approveService.impl;

import com.cn.crmsystem.mapper.approveMapper.ContractsMapper;
import com.cn.crmsystem.pojo.Approve;
import com.cn.crmsystem.pojo.ResultJson;
import com.cn.crmsystem.service.approveService.ContractsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ContractImpl implements ContractsService {
	@Autowired ContractsMapper contractsMapper;
//全查
	@Override
	public ResultJson ContractSelect(Integer userid) {
		List<Approve> list=new ArrayList<>();
		ResultJson resultJson=new ResultJson();
		Map<String,Object> map=new HashMap<>();
		list=contractsMapper.selectAll(userid);
		String msg;
		if(list!=null){
			msg="成 功";
			map.put("全查",list);
			resultJson.getSuccess(msg,map);
		}else{
			msg="失败";
			resultJson.getFail(msg);
		}
		return resultJson;
	}
//修改
	@Override
	public ResultJson UpdateContract(Integer appid, Integer state) {
		ResultJson resultJson=new ResultJson();
		String code;
		String msg;
		if(contractsMapper.UpdateApproveContract(appid,state)>0) {
			code="200";
			msg = "成功";
			resultJson.getSuccess(msg,code);
		}else{
			msg="失败";
			resultJson.getSuccess(msg);
		}
		return resultJson;
	}
//删除
	@Override
	public ResultJson DeleteContract(Integer appid) {
		ResultJson resultJson=new ResultJson();
		String code;
		String msg;
		if(contractsMapper.DeleteApprove(appid)>0) {
			Integer c=contractsMapper.SelectDataid(appid);
			if(c>0){
				Integer d=contractsMapper.DeleteContract(c);
				if(d>0){
					code="200";
					msg = "成 功";
					resultJson.getSuccess(msg,code);
				}else {
					msg="失败";
					resultJson.getSuccess(msg);
				}
			}else {
				msg="失败";
				resultJson.getSuccess(msg);
			}
		}else{
			msg="失败";
			resultJson.getSuccess(msg);
		}
		return resultJson;
	}
//条件查询
	@Override
	public ResultJson SelectConditionContract(Integer userid, Integer state) {
		List<Approve> list=new ArrayList<>();
		ResultJson resultJson=new ResultJson();
		Map<String,Object> map=new HashMap<>();
		list=contractsMapper.selectConditionContract(userid,state);
		String msg;
		if (list!=null){
			msg = "成 功";
			map.put("条件查询",list);
			resultJson.getSuccess(msg,map);
		}else{
			msg="失败";
			resultJson.getSuccess(msg);
		}
		return resultJson;
	}
}
